/**
 * Created by Administrator on 2018/8/2.
 */
//合同文件 覆盖修改
function openDocumentCustomFileUpload(a, b) {
    $("#rightContainer").empty();
    $$http({
        // url: "proinfo/edit/edit-compact.html",
        url: "proinfo/document/documentCustomUpload.html",
        method: 'GET',
        data: {},
        dataType: "application/json"
    }).then(function (a) {
        $$scope.htmlxx = a.data
    }, function (b) {
        //console.log("加载 合同 新增 文件 页面 失败");
    })
}



var customParam = [{
    id: 'deliverTime',
    title: '递送时间',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.deliverTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'resson',
    title: '原因',
    width: 120,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'fileOriginName',
    title: '文件名',
    // width: 150,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'fileDescriptor',
    title: '文件说明',
    type: 'string',
    columnClass: 'text-left',
    hideType: 'lg|md|sm|xs'
}, {
    id: 'version',
    title: '文件版本',
    width: 80,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'createUserId',
    title: '上传人员',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'createTime',
    title: '上传时间',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var date = new Date(record.createTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'operation',
    title: '操作',
    type: 'string',
    width: 120,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        if (record.id) {
            content += '<button class="btn btn-xs btn-success" onclick="alterProjFileContract(\'' + record.fileId + '\',this);"><i class="icon-cloud-upload"></i>  更新</button>';
        }
        content += '  ';
        content += '<button class="btn btn-xs btn-info" onclick="down(\'' + record.fileId + '\');"><i class="icon-cloud-download"></i>  下载</button>';
        content += '<button class="btn btn-xs btn-info" onclick="deleteByUploaderUser2(\'' + record.fileId + '\');"><i class="icon-cloud-download"></i>  删除</button>';
        return content;
    }
}];

var dataInit2 = $CertusJsonAjax.dataInit("listCusFile", {
    projId: proId
}, customParam, 'fileContainer', 'fileToolBarContainer');


function deleteByUploaderUser2(pathId){
    layer.confirm('确认删除此文件？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        $CertusFormAjax.ajax("deleteFileByUploader", {
            removeFileId: pathId
        }, function (res) {
            if(res.data == "success"){
                layer.msg("删除成功");
                dataInit2.refresh(true);
                disprojDocumentSubPage()
            }else if(res.data == "failed"){
                layer.msg("删除失败");
            }
        })
    });

}

//点击 下载 触发 方法
function down(pathId) {
    $CertusFormAjax.ajax("preDownload", {
        pathId: pathId
    }, function (res) {
        if (res.data == "downNow") {
            $CertusFormAjax.download("downloadFile", "fileId=" + pathId);
        } else if (res.data == "overTime") {
            layer.msg("此文件已经过期");
        } else if (res.data == "appling") {
            layer.msg("流程正在审批");
        } else if (res.data == "denied") {
            layer.msg("审批不通过，无法进行下载");
        }else if (res.data == "needApply") {
            layer.confirm('对此文件暂时没有下载权限，是否申请', {
                title: '提示',
                btn: ['申请', '取消'] //按钮
            }, function () {
                //开始申请 权限
                $$scope.applyFile = {};
                //templateCode
                $$scope.applyFile.templateCode = "WJXZQXSPLC";
                $$scope.applyFile.pathId = pathId;
                $CertusJsonAjax.ajax("startApplyDownload", $$scope.applyFile, function (res) {
                    if (res.data == "success") {
                        layer.msg("权限申请成功，请在 由我发起 中查看进度");
                    }
                })


            });
        }
    })
}